{
	UCE - cross-platform game engine written in delphi.
	Copyright (c) 2009, Shutko Vitaly

	This file is part of UCE.

	UCE is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public
	License as published by the Free Software Foundation; either
	version 2.1 of the License, or (at your option) any later version.

	UCE is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
	Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public
	License along with this library; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
}

unit uDrw;

interface

uses
  uTyp, uMat, uGfx;

const
  DRW_FILL = 1;

type
  TDrw = class
    procedure Line(x, y, x2, y2: Single; color: TClr);
    procedure Rect(x, y, w, h: Single; color: TClr; flags: Integer = 0);
    procedure Circle(x, y, r: Single; q: Integer; color: TClr; flags: Integer = 0);
  end;

implementation

uses
  uVar;

procedure TDrw.Line(x, y, x2, y2: Single; color: TClr);
var
  verts: array[0..1] of TGfxVert;
begin
  verts[0] := MakeGfxVert(x, y, 0, 0, color);
  verts[1] := MakeGfxVert(x2, y2, 0, 0, color);

  gfx.NoTex;
  gfx.DrawPrim(GFX_LINES, 1, @verts[0]);
end;

procedure TDrw.Rect(x, y, w, h: Single; color: TClr; flags: Integer = 0);
var
  verts: array[0..4] of TGfxVert;
begin
  verts[0] := MakeGfxVert(x, y, 0, 0, color);
  verts[1] := MakeGfxVert(x + w, y, 0, 0, color);
  verts[2] := MakeGfxVert(x + w, y + h, 0, 0, color);
  verts[3] := MakeGfxVert(x, y + h, 0, 0, color);
  verts[4] := MakeGfxVert(x, y, 0, 0, color);

  gfx.NoTex;

  if flags and DRW_FILL <> 0 then gfx.DrawPrim(GFX_TRIFAN, 2, @verts[0]) else
    gfx.DrawPrim(GFX_LINESTRIP, 4, @verts[0]);
end;

procedure TDrw.Circle(x, y, r: Single; q: Integer; color: TClr; flags: Integer = 0);
var
  verts: array[0..361] of TGfxVert;
  i, start: Integer;
  k: Single;
begin
  if q > 360 then
    q := 360;

  k := 360 / q;
  start := 0;

  if flags and DRW_FILL <> 0 then
  begin
    start := 1;
    verts[0] := MakeGfxVert(x, y, 0, 0, color);
  end;

  for i := start to q + 1 do
    verts[i] := MakeGfxVert(
      x + r * Cos(i * k * MAT_RAD),
      y + r * Sin(i * k * MAT_RAD), 0, 0, color);

  gfx.NoTex;

  if flags and DRW_FILL <> 0 then
    gfx.DrawPrim(GFX_TRIFAN, q, @verts[0]) else
    gfx.DrawPrim(GFX_LINESTRIP, q, @verts[0]);
end;

end.
